package com.hybao.pojo.dao;

import java.util.List;
import java.util.Map;
import java.util.UUID;

import org.springframework.jdbc.core.JdbcTemplate;

import com.hybao.pojo.ormaaping.TaskInfo;

public class TaskInfoDao {
	private JdbcTemplate jdbcTemplate;

	public JdbcTemplate getJdbcTemplate() {
		return jdbcTemplate;
	}

	public void setJdbcTemplate(JdbcTemplate jdbcTemplate) {
		this.jdbcTemplate = jdbcTemplate;
	}
	
	public List<TaskInfo> getTaskInfoWithParams(String uid,String taskid,String catalog, String status){
		String sql = "select STATUS,USER_ID,TASK_ID,PARAMS,CATALOG from HYB_TASK where uid = ?";
		Object[] args = {uid};
		if(taskid != null){
			sql = sql + "and TASK_ID = ?";
			args[args.length + 1] = taskid;
		}
		if(catalog != null){
			sql = sql + "and CATALOG = ?";
			args[args.length + 1] = catalog;
		}
		if(status != null){
			sql = sql + "and STATUS = ?";
			args[args.length + 1] = status;
		}
		return jdbcTemplate.queryForList(sql, TaskInfo.class, args);
	}
	
	public List<Map<String,Object>> getUndoTaskInfoMap(String uid,String taskid,String catalog, String status){
		String sql = "select STATUS,TASK_ID,PARAMS,CATALOG from HYB_TASK where STATUS = 'deal'";
		return jdbcTemplate.queryForList(sql);
	}
	
	public void createTaskfo(TaskInfo taskInfo){
		String sql = "insert into HYB_USER (GMT_CREATE,GMT_MODIFIED,STATUS,USER_ID,TASK_ID,PARAMS,CATALOG) values (now(),now(),?,?,?,?,?)";
		Object[] args = {taskInfo.getStatus(),taskInfo.getUid(),UUID.randomUUID().toString(),taskInfo.getParams(),taskInfo.getCatalog()};
		jdbcTemplate.update(sql, args);
	}
}
